package com.atguigu.gmall.search.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.search.entity.Goods;
import com.atguigu.gmall.search.service.SearchBizService;
import com.atguigu.gmall.search.vo.SearchParamVo;
import com.atguigu.gmall.search.vo.SearchResponseVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/api/inner/search")
@RestController
public class SearchController {

    @Autowired
    SearchBizService searchService;

        /**
     * 更新热度分
     * @param skuId
     * @param hotScore
     * @return
     */
    @GetMapping("/hotscore/{skuId}")
    public Result updateHotScore(@PathVariable("skuId") Long skuId,
                                 @RequestParam("hotScore") Long hotScore){
        searchService.updateHotScore(skuId,hotScore);
        return Result.ok();
    }


    // 检索商品
    @PostMapping("/sku/search")
    public Result<SearchResponseVo> search(@RequestBody SearchParamVo paramVo){

        SearchResponseVo responseVo = searchService.search(paramVo);

        return Result.ok(responseVo);
    }

    // 上架
    @PostMapping("/onsale")
    public Result onSaleGoods(@RequestBody Goods goods){


        searchService.onSaleGoods(goods);

        return Result.ok();
    }


    // 下架
    @DeleteMapping("/cancelSale/{skuId}")
    public Result cancelSale(@PathVariable("skuId") Long skuId){
        searchService.cancelSale(skuId);
        return Result.ok();
    }
}
